package cc.eddic.pratice.programmingparadigms;

import cc.eddic.pratice.programmingparadigms.emp02list.impl.ResultListGcsImpl;
import cc.eddic.pratice.programmingparadigms.exam.MasterDataService;
import cc.eddic.pratice.programmingparadigms.exam.Model.AnswerModel;
import cc.eddic.pratice.programmingparadigms.exam.QuestionBankService;
import cc.eddic.pratice.programmingparadigms.exam.domain.*;
import cc.eddic.pratice.programmingparadigms.exam.impl.*;
import cc.eddic.pratice.programmingparadigms.streampractice.QuestionAndAnswer;
import cc.eddic.pratice.programmingparadigms.streampractice.impl.StreamPracticeLx1Impl;
import cc.eddic.pratice.programmingparadigms.streampractice.impl.StreamPracticeLxImpl;
import com.alibaba.excel.util.StringUtils;
import lombok.Getter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Array;
import java.util.*;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Collectors;

public class Test {

    public static void main(String[] args) {
        final Logger log = LoggerFactory.getLogger(ResultListGcsImpl.class);
        QuestionBankServiceLxImpl questionBankServiceLx=new QuestionBankServiceLxImpl();

        StreamPracticeLx1Impl streamPracticeLx=new StreamPracticeLx1Impl();
        streamPracticeLx.mapToQuestionAndAnswer(questionBankServiceLx.importCorrectAnswers(""));

//        List<QuestionAndAnswer> questionAndAnswerList=streamPracticeLx.mapToQuestionAndAnswer();
//        for()
//        ExamServiceLxImpl examServiceLx=new ExamServiceLxImpl();
//        List<ExamServiceLxImpl.StudentScore> studentScoreList = examServiceLx.score();
//        for(ExamServiceLxImpl.StudentScore s:studentScoreList){
//            System.out.print(s.getStudentName()+":"+s.getScore());
//        }
//         Map<String, Integer> score= examServiceLx.getScore();
//         System.out.print("aaaaaaaaa"+score);

//        自己做的统计总分
        /*
        ExamServiceLxImpl examServiceLx=new ExamServiceLxImpl();
        QuestionBankServiceLxImpl questionBankServiceLx=new QuestionBankServiceLxImpl();
//        算总分
        List<Answer> answerList=examServiceLx.importAnswers("");
        Map<Integer,Character> correctAnswerMap=questionBankServiceLx.readCorrectAnswers2("");
        Map<String,Integer> scoreMap=new HashMap<>();
        for(Answer a:answerList){
            if (log.isDebugEnabled()) log.debug("题号: {},选项:{}", a.getQuestion().getNo(),a.getChoice());
            String name=a.getStudent().getName();
            if (log.isDebugEnabled()) log.debug("姓名: {}", name);
            Option option = a.getQuestion().getOptions().stream().filter(x->x.isCorrectAnswer()).findFirst()
                    .orElseThrow(()->new IllegalArgumentException("没找到正确的"));
            if (log.isDebugEnabled()) log.debug("答对的题目: {}", option.getChoice());

            if(option.getChoice()==a.getChoice()){
                if(scoreMap.containsKey(name)){
                    scoreMap.put(name,scoreMap.get(name)+4);
                }else{
                    scoreMap.put(name,4);
                }
            }
            System.out.print(scoreMap.entrySet());
        }*/
//        importCorrectAnswers
        /*final Logger log = LoggerFactory.getLogger(ResultListGcsImpl.class);
        QuestionBankServiceLxImpl questionBankServiceLx=new QuestionBankServiceLxImpl();
            String f = "1\t2\t3\t4\t5\t6\t7\t8\t9\t10\n" +
                    "B\tC\tA\tC\tD\tB\tB\tA\tD\tB\n" +
                    "11\t12\t13\t14\t15\t16\t17\t18\t19\t20\n" +
                    "B\tC\tA\tC\tA\tB\tD\tC\tD\tB\n" +
                    "21\t22\t23\t24\t25\n" +
                    "A\tD\tA\tC\tB";
            String[] file=f.split("\n");
            Map<Integer,Character> answerMap = new HashMap<>();
            for(int i=0;i<file.length;i+=2){
                String[] no=file[i].split("\t");
                String[] cho=file[i+1].split("\t");
                for(int j=0;j<no.length;j++){
                    int number=Integer.parseInt(no[j]);
                    char choice=cho[j].charAt(0);
                    answerMap.put(number,choice);
                    if (log.isDebugEnabled()) log.debug("answerMap: {}", answerMap.get(number));
                }
            }
        List<Question> questionList=questionBankServiceLx.importQuestions("");
        for(Question q:questionList){
            if(!answerMap.containsKey(q.getNo())){
                continue;
            }
            char choice=answerMap.get(q.getNo());
            if (log.isDebugEnabled()) log.debug("正确答案choice: {}", choice);
            Option option=q.getOptions().stream().filter(o->o.getChoice()==(choice)).findFirst()
                    .orElseThrow(()->new IllegalArgumentException("没找到该选项"));
            option.changeToCorrectAnswer();
            if (log.isDebugEnabled()) log.debug("问题{},问题中的正确的选项: {}，问题中的选项状态: {}", q.getNo(),option.getChoice(),option.isCorrectAnswer());
        }
//        for(Question o:questionList){
//            System.out.print(o.getNo());
//        }
*/
        /*MasterDataService masterDataService = new MasterDataServiceGcsImpl();
        QuestionBankService questionBankService = new QuestionBankServiceGcsImpl();

        String content = "试题编号,李惠,谭雨晴,李馨,曾奕哲,车晓满,王巧家,孙晨玮,崔相元,韩睿洁\n" +
                "1,B,B,B,B,B,B,B,B,C\n" +
                "2,C,C,C,C,C,C,C,C,C\n" +
                "3,A,A,A,A,A,B,A,A,A\n" +
                "4,C,C,C,C,C,C,C,B,C\n" +
                "5,D,D,D,D,D,D,D,D,D\n" +
                "6,B,B,B,B,B,D,B,A,B\n" +
                "7,B,B,B,B,B,C,B,C,B\n" +
                "8,A,A,C,A,A,A,A,A,A\n" +
                "9,D,D,D,D,D,D,A,D,D\n" +
                "10,D,B,D,B,D,D,B,D,D\n" +
                "11,B,A,B,C,A,A,A,A,A\n" +
                "12,C,A,C,A,B,C,C,C,C\n" +
                "13,A,A,B,A,A,A,A,A,B\n" +
                "14,A,A,C,C,D,C,A,C,C\n" +
                "15,A,A,A,A,A,B,A,B,A\n" +
                "16,B,B,B,B,B,B,B,B,B\n" +
                "17,A,C,D,D,D,D,D,D,D\n" +
                "18,C,C,C,C,C,C,C,C,C\n" +
                "19,D,D,D,D,D,D,C,A,D\n" +
                "20,B,B,B,B,B,B,B,B,B\n" +
                "21,D,C,C,A,D,D,,A,\n" +
                "22,D,D,D,,D,C,,C,C\n" +
                "23,A,A,A,A,D,D,,C,C\n" +
                "24,C,C,C,C,C,D,A,C,D\n" +
                "25,B,B,B,B,B,B,,D,B";
        List<Answer> answers = new ArrayList<>();
        String[] header = new String[0];

        Exam exam = masterDataService.find(masterDataService.getExams(), x -> "7-12 开营考试".equals(x.getName()))
                .orElseThrow(() -> new IllegalArgumentException("找不到 7-12 开营考试"));
        List<Question> questionList = questionBankService.importQuestions("");

        for (String line : content.split("\n")) {
            if (log.isDebugEnabled()) log.debug("aaaaaa"+line);
            String[] values = line.split(",", -1);
            if (log.isDebugEnabled()) log.debug("length : {}", values.length);
            // 表头（包含学生的姓名信息）
            if (header.length == 0) {
                header = values;
                continue;
            }
            if (values.length < 1) {
                continue;
            }
        }
        for(String s:header){
            System.out.print(s);
        }
*/
    }



}
